Skip to main content
Version: 0.6.0

getFasterFuncCb

This method takes any number of arbitrary async functions as input and returns the fastest function in terms of execution time in a callback function.

Params

getFasterFuncCb([inputFunction1,inputFunction2,inputFunction3,...],cb);
  • inputFunctionN... → The functions we want to compare their execution time with each other and return the fastest one
  • cb → A function that will be called as a callback and the output will be passed to this function
Take care

When you use this method, be sure to define the callback function

Returns

cb(err,fasterFunc){
//codes
}
  • err → In case of any problem that causes this method to not be able to find the fastest function, it will return the error in this parameter.
  • fasterFunc → The fastest function in terms of execution time is placed in this parameter

Usage

const testFunction1 = () => {
const inpFuncSync1 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
});
};

const inpFuncSync2 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 500);
});
};

const inpFuncSync3 = async () => {
return await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 3000);
});
};

getFasterFuncCb([inpFuncSync1,inpFuncSync2,inpFuncSync3],(err,fasterFunc)=>{
console.log(fasterFunc);//[AsyncFunction: inpFuncSync2]
})